package com.compus.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.compus.constant.OrderStatus;
import com.compus.entity.po.Order;
import com.compus.entity.vo.OrderVo;
import com.compus.mapper.OrderMapper;
import com.compus.service.OrderService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Override
    public List<OrderVo> listOrder() {
        return baseMapper.listOrder(StpUtil.getLoginIdAsLong());
    }

    @Override
    public void processOrder(String msg) {
        JSONObject parsed = JSONUtil.parseObj(msg);
        Long orderId = parsed.getLong("orderId");
        lambdaUpdate()
                .eq(Order::getId, orderId)
                .set(Order::getStatus, OrderStatus.FINISH)
                .update();
    }
}
